#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* insertAtHead(struct Node* head, int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = head;
    return newNode;
}

struct Node* deleteNode(struct Node* head, int key) {
    struct Node* temp = head, * prev = NULL;

    if (temp != NULL && temp->data == key) {
        head = temp->next; 
        free(temp); 
        return head;
    }

    while (temp != NULL && temp->data != key) {
        prev = temp;
        temp = temp->next;
    }

    if (temp == NULL) return head;

    prev->next = temp->next;

    free(temp);

    return head;
}

void printList(struct Node* node) {
    while (node != NULL) {
        printf("%d ", node->data);
        node = node->next;
    }
    printf("\n");
}

int main() {
    struct Node* head = NULL;
    int num;

    while (scanf("%d", &num) && num != -1) {
        head = insertAtHead(head, num);
    }

    int deleteValue;
    scanf("%d", &deleteValue);

    head = deleteNode(head, deleteValue);

    printList(head);

    return 0;
}
